package com.guopiao.vat.common.util;


import com.guopiao.vat.common.general.constants.InvoiceState;
import com.guopiao.vat.common.general.response.GeneralResponse;

/**
 *  
 *  * @Author: Xander Xiao
 *  * @Description: 全局通用返回工具类
 *  @Date:Create in 2017/12/26
 *  
 */

public class ResponseUtil {
    /**
     * 请求成功返回
     * @param object
     * @return
     */
    public static GeneralResponse success(String requestId, String code, String msg, Object object){
        GeneralResponse generalResponse=new GeneralResponse();
        generalResponse.setRequestId(requestId==null?"":requestId);
        if (StringUtil.isEmpty(code)) {
            generalResponse.setRtnCode(InvoiceState.SUCCEED.getCode());
        } else {
            generalResponse.setRtnCode(code);
        }
        if (StringUtil.isEmpty(msg)) {
            generalResponse.setRtnMsg(InvoiceState.SUCCEED.getMsg());
        } else {
            generalResponse.setRtnMsg(msg);
        }
        generalResponse.setRtnData(object == null?"":object);
        return generalResponse;
    }
    /**
     * 请求成功返回（无业务数据返回）
     * @param
     * @return
     */
    public static GeneralResponse success(){
        return success(null,null,null,null);
    }
    public static GeneralResponse error(String requestId,String rtnCode,String rtnMsg){
        GeneralResponse generalResponse=new GeneralResponse();
        generalResponse.setRequestId(requestId);
        generalResponse.setRtnCode(rtnCode);
        generalResponse.setRtnMsg(rtnMsg);
        generalResponse.setRtnData("");
        return generalResponse;
    }
}
